import React from 'react';

import './index.less';

import { createPage } from 'nc-lightapp-front';
import { render } from 'src/hrpub/common/frame';
import MainAction from '../actions/main';
import ButtonAction from '../actions/btn';
import TableAction from '../actions/table';
import FormAction from '../actions/form';
import DateAction from '../actions/date';
import QryEntryAction from '../actions/qryEntry';
import EntryAction from '../actions/entry';
import EmptyImg from 'src/hrpub/common/components/emptyImg';
import Pagination from 'src/hrpub/common/components/Pagination';
import Layout from 'src/hrpub/common/components/Layout';
import AddPage from '../components/AddPage';
import AdjustDateModal from '../components/AdjustDateModal';
import { base } from 'nc-lightapp-front';
import { THEME } from '../../../public/theme/theme';
import {COMMON} from "../common/common";

const { Header, Content } = Layout;
const HomePage = render({
	actions: {
		mainAct: MainAction,
		btnAct: ButtonAction,
		tableAct: TableAction,
		formAct: FormAction,
		dateAct: DateAction,
		entryAct: EntryAction,
		qryEntryAct: QryEntryAction
		//rowAct: RowHandleAction
	}
})(({ props, action, state }) => {
	const { emp, button, editTable, search } = props;
	return (
		<div className={`entry-register ${THEME.bgCommon}`}>
			<Choose>
				<When condition={emp.page === 'main'}>
					<Layout className="employing-page">
						<Header
							className={'header'}
							showButtons={!!(emp.orgValue && emp.orgValue.refpk)}
							showOrgRefer={emp.showOrgRefer}
							orgReferOptions={{
								getOrgData: action.btnAct.changeOrg,
								orgVal: emp.orgValue,
								showEmpty: emp.widget?true:false
							}}
							buttonOptions={{
								area: 'head',
								onButtonClick: action.btnAct.headerClick
							}}
							button={button}
						/>
						<Content>
							<div className="employing-main-table-wrapper">
								<div className="mainTable">
									<If condition = {emp.orgValue.refpk || emp.widget}>
										{ 
											editTable.createEditTable('list', {
												showCheck: false,
												onSelectedAll: action.tableAct.selectAll,
												onRowDoubleClick: action.tableAct.doubleClick,
												// height: action.tableAct.getMainTableHeight()
												adaptionHeight:true,
                                				otherAreaHeight:emp.pageInfo.total ? 50:0,
											})}
									</If>
								</div>
								<If condition = {emp.orgValue.refpk || emp.widget}>
									{emp.pageInfo.total > 0 &&(
										<div
											style={{
												marginTop: '5px'
											}}
										>
											<Pagination
												current={emp.pageInfo.pageIndex}
												pageSize={emp.pageInfo.pageSize}
												total={emp.pageInfo.total}
												showSizeChanger={true}
												showQuickJumper={true}
												onChange={action.mainAct.turnPage}
												onShowSizeChange={action.mainAct.changePageSize}
											/>
										</div>
									)}
								</If>
							</div>
						</Content>
					</Layout>
					{!emp.orgValue.refpk && !emp.widget && (
						<div className={'wrapper-empty-box'}>
							<EmptyImg text={emp.language['gx6008-000084']} />
						</div>
					)}
				</When>
				<When condition={emp.page === 'browse' || emp.page === 'edit'}>
					<AddPage {...props} />
				</When>
			</Choose>
			<AdjustDateModal
				visible={emp.offerContentModalVisible}
				language={emp.language}
				beginDate={emp.beginDate}
				beginDateOri={emp.beginDateOri}
				closeModal={action.dateAct.closeDateModal}
				sendDate={action.dateAct.sendDate}
				onChange={action.dateAct.onChange}
			/>
			<div
				style={{
					display: 'none'
				}}
			>
				{search.NCCreateSearch('query', {
					clickSearchBtn: action.mainAct.toSearch
				})}
			</div>
		</div>
	);
});
let pagecode = COMMON.appConfig.pagecode;
let billinfo=[];
let grid = ["list","material","hi_psndoc_work","hi_psndoc_edu","hi_psndoc_family"];
let form = ["card","hi_psndoc_ctrt","bd_psndoc"];
grid.forEach(gridId=>{
	let temp = {
        billtype: 'grid',
        pagecode,
        bodycode:gridId//紧急联系人
	};
	billinfo.push(temp)
});
form.forEach(formId=>{
	let temp = {
        billtype: 'form',
        pagecode,
        headcode:formId//紧急联系人
	};
    billinfo.push(temp)
});

export default createPage({billinfo})(HomePage);
